package airportCoordinationMonitor;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

import org.json.JSONObject;

public class Sender {
	
	public static void ping(int port, String ping_msg)
	{
		try{
			DatagramSocket sock = new DatagramSocket();
			byte[] msg = ping_msg.getBytes();
			DatagramPacket packet = new DatagramPacket(msg, msg.length, InetAddress.getByName("localhost"), port);
			sock.send(packet);
		}catch(Exception e){ System.out.print("Error sending packet: " + e.getMessage() + "\n"); }
	}
	
	public static void activate(int port)
	{
		JSONObject activation = new JSONObject();
		
		try{
			activation.put("type", "ACTIVATE");
		}catch(Exception e){ System.out.print("Error generating activation: " + e.getMessage() + "\n"); return;}
		
		try{
			DatagramSocket sock = new DatagramSocket();
			byte[] msg = activation.toString().getBytes();
			DatagramPacket packet = new DatagramPacket(msg, msg.length, InetAddress.getByName("localhost"), port);
			sock.send(packet);
		}catch(Exception e){ System.out.print("Error sending packet: " + e.getMessage() + "\n"); }		
	}
}
